//package com.alibaba.cirtus.ots.application.app.ability.facade;
//
//import com.alibaba.cz.base.tool.log.Log;
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.epoch.app.otsapplicationappsdk.customdetail.dto.AsyncRequest;
//import com.epoch.app.otsapplicationappsdk.customdetail.dto.RenderRequest;
//import com.epoch.app.otsapplicationappsdk.customdetail.service.CustomDetailService;
//
//import com.epoch.app.otsplatformenhance.model.dto.PageQueryAddressListRequest;
//import com.epoch.app.otsplatformenhance.model.dto.PageQueryAddressListResponse;
//import com.epoch.app.otsplatformenhance.model.dto.QueryCustomerInfoRequest;
//import com.epoch.app.otsplatformenhance.model.dto.QueryCustomerInfoResponse;
//import com.epoch.app.otsplatformenhance.service.OtsPlatformEnhanceService;
//import com.fasterxml.jackson.annotation.JsonInclude;
//import com.fasterxml.jackson.annotation.JsonProperty;
//import com.fasterxml.jackson.annotation.JsonPropertyOrder;
//import org.apache.commons.collections.CollectionUtils;
//import org.springframework.beans.BeanUtils;
//import org.springframework.beans.BeansException;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.math.BigDecimal;
//import java.math.RoundingMode;
//import java.text.DecimalFormat;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Objects;
//
//@Service
//public class CustomDetailServiceImpl implements CustomDetailService {
//
//    private static Log log = Log.getLogger(CustomDetailServiceImpl.class);
//
//    @Autowired
//    private OtsPlatformEnhanceService otsPlatformEnhanceService;
//
//    @Override
//    public Object render(RenderRequest renderRequest) {
//        log.info("客户详情渲染页面请求参数 {} ", JSONObject.toJSONString(renderRequest));
//
//        JSONObject result = new JSONObject();
//        int limit = 10;
//        if (renderRequest.getPageSize() != null && renderRequest.getPageSize() > 0) {
//            limit = renderRequest.getPageSize();
//        }
//        if (renderRequest.getCurrentPage() == null) {
//            renderRequest.setCurrentPage(1);
//        }
//        try {
//            PageQueryAddressListRequest addressListRequest = new PageQueryAddressListRequest();
//            BeanUtils.copyProperties(renderRequest, addressListRequest);
//            addressListRequest.setCustomerCode(renderRequest.getCustomerCode());
//            addressListRequest.setPage(renderRequest.getCurrentPage());
//            addressListRequest.setSize(limit);
//            PageQueryAddressListResponse addressListResponse = otsPlatformEnhanceService.pageQueryAddressList(addressListRequest);
//            result.put("addressListResponse", addressListResponse.getResult());
//
//            QueryCustomerInfoRequest customerInfoRequest = new QueryCustomerInfoRequest();
//            customerInfoRequest.setCode(renderRequest.getCustomerCode());
//            QueryCustomerInfoResponse customerInfoResponse = otsPlatformEnhanceService.queryCustomerInfo(customerInfoRequest);
//            result.put("customerInfoResponse", customerInfoResponse.getResult());
//
//            int totalPage = addressListResponse.getTotal() / limit;
//            if (addressListResponse.getTotal() % limit > 0) {
//                totalPage++;
//            }
//            result.put("totalPage", totalPage);
//
//            result.put("success", true);
//            result.put("message", "");
//
//        } catch (BeansException e) {
//            result.put("success", false);
//            result.put("message", "页面跑丢了");
//        }
//        return result;
//    }
//
//    @Override
//    public Object async(AsyncRequest asyncRequest) {
//        log.info("客户详情异步 请求参数 {} ", JSON.toJSONString(asyncRequest));
//
//        Object request = asyncRequest.getRequest();
//        if (Objects.isNull(request)) {
//            return null;
//        }
//        JSONObject result = new JSONObject();
//        try {
//            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(request));
//            JSONObject fields = jsonObject.getJSONObject("fields");
//            String customerCode = fields.getString("customerCode");
//            Integer currentPage = fields.getInteger("currentPage");
//            Integer pageSize = fields.getInteger("pageSize");
//            int limit = 10;
//            if (pageSize != null && pageSize > 0) {
//                limit = pageSize;
//            }
//            if (currentPage == null) {
//                currentPage = 1;
//            }
//            QueryCustomerInfoRequest customerInfoRequest = new QueryCustomerInfoRequest();
//            customerInfoRequest.setCode(customerCode);
//            QueryCustomerInfoResponse customerInfoResponse = otsPlatformEnhanceService.queryCustomerInfo(customerInfoRequest);
//            result.put("customerInfoResponse", customerInfoResponse.getResult());
//
//            PageQueryAddressListRequest addressListRequest = new PageQueryAddressListRequest();
//            addressListRequest.setCustomerCode(customerCode);
//            addressListRequest.setPage(currentPage);
//            addressListRequest.setSize(limit);
//            PageQueryAddressListResponse addressListResponse = otsPlatformEnhanceService.pageQueryAddressList(addressListRequest);
//            if (addressListResponse == null) {
//                throw new Exception("未查到结果");
//            }
//            result.put("success", addressListResponse.getSuccess());
//            result.put("addressListResponse", addressListResponse.getResult());
//            result.put("pageSize", limit);
//            result.put("currentPage", currentPage);
//            result.put("total", addressListResponse.getTotal());
//            int totalPage = addressListResponse.getTotal() / limit;
//            if (addressListResponse.getTotal() % pageSize > 0) {
//                totalPage++;
//            }
//            result.put("totalPage", totalPage);
//        } catch (Exception e) {
//            result.put("success", false);
//            result.put("message", "页面跑丢了");
//        }
//        return result;
//    }
//
//}
